<?php
/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Game
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
class Game_Model_DbTable_Distributors extends Engine_Db_Table
{
  protected $_rowClass = 'Game_Model_Distributor';
  
  protected $_serializedColumns = array('config');
  
  protected $_distributors;

  protected $_distributorsAssoc = array();

  protected $_activeDistributors;
  
  public function getDistributor($type)
  {
    if( null === $this->_distributors ) {
      $this->getDistributors();
    }

    if( !empty($this->_distributorsAssoc[$type]) ) {
      return $this->_distributorsAssoc[$type];
    }

    return null;
  }
  
  public function getDistributors()
  {
    if( null === $this->_distributors ) {
      $this->_distributors = $this->fetchAll();
      foreach( $this->_distributors as $distributor ) {
        $this->_distributorsAssoc[$distributor->type] = $distributor;
      }
    }

    return $this->_distributors;
  }

  public function getDistributorsAssoc()
  {
    if( null === $this->_distributors ) {
      $this->getDistributors();
    }
    
    return $this->_distributorsAssoc;
  }

  public function hasDistributor($type)
  {
    return !empty($this->_distributorsAssoc[$type]);
  }
  
}
